﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PortalCurriculo.WebUI.UserControls.Basico
{
    public partial class ImageButton : UserControl
    {
        private static readonly object EventClick = new object();

        [UrlProperty]
        public string ImageUrl
        {
            set
            {
                Image.ImageUrl = value;
                Image.Visible = value != null;
            }
        }

        [CssClassProperty]
        public string ImageCssClass
        {
            set { Image.CssClass = value; }
        }

        [CssClassProperty]
        public string LinkCssClass
        {
            set { Link.CssClass = value; }
        }

        [CssClassProperty]
        public string CssClass
        {
            set { div.Attributes["class"] += value; }
        }

        public string Text
        {
            set { Link.Text = value; }
        }

        public Orientation Orientation
        {
            set
            {
                Line.Visible = value == Orientation.Vertical;

                if (value == Orientation.Vertical)
                    div.Style.Add("text-align", "center");
            }
        }

        [UrlProperty]
        public string PostBackUrl
        {
            set { Link.PostBackUrl = Image.PostBackUrl = value; }
        }

        protected virtual void OnClick(EventArgs e)
        {
            var onClickHandler = (EventHandler) Events[EventClick];
            if (onClickHandler != null) onClickHandler(Link, e);
        }

        public event EventHandler Click
        {
            add
            {
                Events.AddHandler(EventClick, value);
                Link.Click += value;
            }
            remove
            {
                Events.RemoveHandler(EventClick, value);
                Link.Click -= value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}